
import { getData, getMonthData, getYearData } from './request.js'
import { formatDate, mapformatData } from '@/library/utils.js'
export default async (store, type, date) => {
  let data = null
  switch (type) {
    case 'day':
      data = await getData(date)
      break
    case 'month':
      data = await getMonthData(date)
      break
    case 'year':
      data = await getYearData(date)
      break
  }
  if (data.data.error_code !== 0) {
    store.commit('setErrorCode', data.data.error_code)
    return
  } else {
    store.commit('setErrorCode', data.data.error_code)
  }
  let res = null
  switch (type) {
    case 'day':
      res = data.data.result.data
      res.date = formatDate(res.date, type)
      res['year-month'] = formatDate(res['year-month'], 'month')
      break
    case 'month':
      res = data.data.result.data.holiday_array
      res.festival = mapformatData(res, 'festival', 'day')
      break
    case 'year':
      res = data.data.result.data.holiday_list
      res = mapformatData(res, 'startday', 'day')
      break
  }
  store.commit('setData', { type, data: res })
}
